public class Test5 {

    public static void main(String[] args) {
        int[] arr1 = {1,2,3,4};
        int[] arr2 = new int[10];
        int[] arr3 = new  int[]{1,2,3,4,5,6,7,8,9,10};
        System.out.println(arr1);
        System.out.println(arr2);
        System.out.println(arr3);
        char[] arr5 = new char[10];
        System.out.println(arr5);
        System.out.println(arr1[0]);
        System.out.println(arr1[1]);
        System.out.println(arr1[2]);
        System.out.println(arr1[3]);
        System.out.println(arr1.length);
        for (int i = 0; i < arr3.length; i++) {
            System.out.println(arr3[i]);
        }
        for (int x: arr3){
            System.out.print(x + " ");
        }
    }
    public static int facNum(int n){
        //斐波那契数列
        if(n == 1){
            return 0;
        }else if(n==2){
            return  1;
        }
        else
            return facNum(n-2)+facNum(n-1);
    }
    public static int facNum1(int n){
        //面试写这种写法
        if(n == 1){
            return 0;
        }else if(n == 2){
            return 1;
        }
        int f1 = 0;
        int f2 = 1;
        int f3 = -1;
        for (int i = 3; i <= n ; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }return f3;
    }
    public static void main9(String[] args) {
        System.out.println(facNum(5));
        System.out.println(facNum1(40));
    }
    public static int numSum(int n){
        if(n < 10){
            return n % 10;
        }
        return n % 10+ numSum(n/10);
    }
    public static void main8(String[] args) {
        //求一个整数每一位加起来的和
        int ret = numSum(1978);
        System.out.println(ret);
    }
    public static int addSum(int n){
        if(n == 1){
            return 1;
        }
        return n+addSum(n-1);
    }
    public static void main7(String[] args) {
        //求1~10的和
        System.out.println(addSum(10));
    }
    public static void facDo(int n) {
        if(n < 10){
            System.out.println(n % 10);
            return;
        }else {
            facDo(n/10);
        System.out.println(n % 10);
    }
    }
    public static void main6(String[] args) {
        //按顺序输出整数
        facDo(123);
    }
    public static int facFun(int n) {
        if(n==1)
            return 1;
        else
            return n * facFun(n-1);
    }
    public static void main5(String[] args) {
      int ret = facFun(5);
        System.out.println(ret);
        System.out.println(facFun(4));
    }
    public static int add(int a,int b){
        return a+b;
    }
    public static double add(double a,double b){
        return a+b;
    }
    public static void main4(String[] args) {
        //方法重载
        int a = 20;
        int b = 10;
        int ret1 = add(a,b);
        System.out.println(ret1);
        double c = 0.45;
        double d = 0.56;
        double ret2 = add(c,d);
        System.out.println(ret2);

    }
    public static int fac(int n){
        int ret = 1;
        for (int i = 1; i <= n; i++) {
             ret *= i;
        }
        return ret;
    }
    public static int facSum(int n){
        int sum = 0;
        for (int i = 1; i <= n ; i++) {
            sum += fac(i);
        }
        return sum;
    }
    public static void main3(String[] args) {
        int n = 5;
        System.out.println(fac(n));
        System.out.println(facSum(n));
    }
    public static boolean isLeapyear(int year){
        if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
            return true;
        }return false;
    }
    public static void main2(String[] args) {
        int year = 2020;
     boolean c = isLeapyear(2020);
        System.out.println(c);
    }
//    public static int add(int a,int b){
//        return a+b;
//    }
    public static void main1(String[] args) {
        int a = 10;
        int b = 20;
        int c = add(a,b);
        System.out.println(c);
    }
}
